package com.example.wendao.view.adapter;

import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.paging.PagedListAdapter;
import androidx.recyclerview.widget.DiffUtil;
import com.example.wendao.model.entity.User;
import com.example.wendao.view.viewholder.JumpToDetailTestViewHolder;
import com.example.wendao.view.viewholder.UserViewHolder;

public class UserListAdapter extends PagedListAdapter<User, JumpToDetailTestViewHolder> {

    @NonNull
    @Override
    public JumpToDetailTestViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new JumpToDetailTestViewHolder(parent);
    }

    @Override
    public void onBindViewHolder(@NonNull JumpToDetailTestViewHolder holder, int position) {
        User user = getItem(position);
        if (user != null)
            holder.bindTo(user);
    }

    public UserListAdapter() {
        super(DIFF_CALLBACK);
    }

    private static DiffUtil.ItemCallback<User> DIFF_CALLBACK = new DiffUtil.ItemCallback<User>() {
        @Override
        public boolean areItemsTheSame(User oldUser, User newUser) {
            return oldUser.getUserId() == newUser.getUserId();
        }

        @Override
        public boolean areContentsTheSame(@NonNull User oldUser, @NonNull User newUser) {
            return oldUser.equals(newUser);
        }

    };


}
